require(["common", "coAjax", "queryString", "routie", "title"], function(jSouper, coAjax, QueryString, routie, title) {
	var get_goods_type;
	//放置监听HASH变动
	routie({
		"*": function(hash) {
			var queryString = new QueryString(location.hash);
			console.log(queryString);
			get_goods_type = queryString.get("id");
			App.set("$Cahce.goods_list_type", get_goods_type);
			if (get_goods_type == 2) {
				console.log("热销商品")
				App.set("$Cache.goods_info.type", "热销商品");
				title("热销商品");
				goods_list_url = appConfig.goods.quality_list;
			} else if (get_goods_type == 3) {
				console.log("新品上市")
				App.set("$Cache.goods_info.type", "新品上市");
				title("新品上市");
				var goods_list_url = appConfig.goods.list;
			} else {
				console.log("商品分类")
				App.set("$Cache.goods_info.type", "商品分类");
				title("商品分类");
				var goods_list_url = appConfig.goods.list;
			}

			//页号
			var current_page_num = ~~queryString.get("page");
			console.log(current_page_num);
			//每页显示数量
			var goods_pre_num = ~~queryString.get("num") || appConfig.goods_pre_num || 12;
			App.set("config.goods_pre_num", goods_pre_num);
			App.set("$Cache.goods_pre_num", goods_pre_num);
			jSouper.ready(function(argument) {
				App.set("$Cache.current_page_num", current_page_num);
			});
			//获取指定页的商品
			coAjax.get(goods_list_url, {
				bus_id: appConfig.bus_id,
				num: goods_pre_num,
				page: current_page_num
			}, function(result) {
				jSouper.ready(function() {
					App.set("goods", result.result);
				});
			});
			//获取所有商品数量
			coAjax.get(appConfig.goods.number, {
				bus_id: appConfig.bus_id,
			}, function(result) {
				jSouper.ready(function() {
					var number = ~~result.result
					App.set("$Cache.goods_number", number);
					var _goods_number_list = [];
					_goods_number_list.length = number;
					var _page_num = [];
					//向上取整获取页数
					// console.log(number, goods_pre_num, Math.ceil(number / goods_pre_num));
					_page_num.length = Math.ceil(number / goods_pre_num);
					App.set("$Cache.goods_number_list", _goods_number_list);
					App.set("$Cache.page_num", _page_num);
				});
			});
			//------------
		}
	});

});